package com.liwang.lanouhn.nvshengo.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.liwang.lanouhn.nvshengo.Info.Info;
import com.liwang.lanouhn.nvshengo.Info.LunBoInfo;
import com.liwang.lanouhn.nvshengo.R;
import com.liwang.lanouhn.nvshengo.fragments.FeatureFragment;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

/**
 * Created by lanouhn on 2016/10/19.
 */
public class LunBoDetailsActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView iv_lunbo_back;
    private TextView tv_lunbo_title;
    private ImageView iv_lunbo_share;
    private FrameLayout fm_layout;
    private FeatureFragment featureFragment;
    private android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
    private android.support.v4.app.FragmentTransaction transaction;
    private LunBoInfo lunboinfo =new LunBoInfo();
    private Info info =new Info();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        int flag= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        Window window=getWindow();
        window.setFlags(flag,flag);
        setContentView(R.layout.activity_lunbodetails);
        initView();
        initData();
    }
    private void initView() {
        iv_lunbo_back = (ImageView) findViewById(R.id.iv_lunbo_back);
        iv_lunbo_back.setOnClickListener(this);
        tv_lunbo_title = (TextView) findViewById(R.id.tv_lunbo_title);
        iv_lunbo_share = (ImageView) findViewById(R.id.iv_lunbo_share);
        iv_lunbo_share.setOnClickListener(this);
        fm_layout= (FrameLayout) findViewById(R.id.fm_layout);

    }

    private void initData() {

        info= (Info) getIntent().getSerializableExtra("info");
        featureFragment= FeatureFragment.newInstants(info);
        transaction=fm.beginTransaction();
        transaction.add(R.id.fm_layout,featureFragment);
        transaction.commit();
        tv_lunbo_title.setText(info.getTitle());
    }



    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_lunbo_back:
                finish();
                break;
            case R.id.iv_lunbo_share:
                showShare();
                break;
        }

    }
    private void showShare() {
        ShareSDK.initSDK(this);
        OnekeyShare oks = new OnekeyShare();
//关闭sso授权
        oks.disableSSOWhenAuthorize();

// title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
        oks.setTitle("女神 go!");
// titleUrl是标题的网络链接，QQ和QQ空间等使用
        oks.setTitleUrl(lunboinfo.getLink());
// text是分享文本，所有平台都需要这个字段
        oks.setText(lunboinfo.getTitle());
// imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
//oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
// url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl(lunboinfo.getLink());
// comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("你的私人定制美丽管家");
// site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite(getString(R.string.app_name));
// siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl(lunboinfo.getLink());

// 启动分享GUI
        oks.show(this);
    }
}
